class AttachmentController < ApplicationController
  def showfile
    attachment = Attachment.find(:first, :conditions=>["gencode=?", params[:id]])
		path = "#{RAILS_ROOT}/public/files/#{attachment.id}"
		data = read_binary(path)
    filename = "filename"
    begin
      filename = attachment.filename
    rescue
      if attachment.content_type=="application/msword"
        filename = "filename.doc"
      elsif attachment.content_type=="application/pdf"
        filename = "filename.pdf"
      elsif attachment.content_type=="application/vnd.ms-excel"
        filename = "filename.xls"
      else
        filename = "filename"
      end
    end
		send_data(data, :filename=>filename, :type=>attachment.content_type, :disposition=>"attachment")
  end
end
